package com.haojin.spring;

import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;

/**
 * @author .29.
 * @create 2023-03-01 11:21
 */
public class testPersonValidator {
    public static void main(String[] args){
        Person person = new Person();
//        person.setName("高启强");
//        person.setAge(29);

        //创建person对象的DataBinder
        DataBinder binder = new DataBinder(person);

        //设置校验
        binder.setValidator(new PersonValidator());

        //校验(当person属性值为空时，校验不通过)
        binder.validate();

        //输出校验结果
        //binder.getBindingResult() 获取校验结果对象
        //bindingResult.getAllErrors() 获取所有校验到的错误
        BindingResult bindingResult = binder.getBindingResult();
        System.out.println(bindingResult.getAllErrors());

    }
}
